<?php

namespace Drupal\shusy_vip\ViewsController;

use Drupal\shusy_vip\ViewsController\handler\field\ShusyVipAmountViewsField;
use Drupal\shusy_vip\ViewsController\handler\field\ShusyVipEditLinkViewsField;
use Drupal\shusy_vip\ViewsController\handler\field\ShusyVipIsDefaultViewsField;
use Drupal\shusy_vip\ViewsController\handler\field\ShusyVipRebateViewsField;
use Drupal\shusy_vip\ViewsController\handler\field\ShusyVipStatusViewsField;
use Drupal\shusy_vip\ViewsController\handler\filter\ShusyVipIsDefaultViewsFilter;
use Drupal\shusy_vip\ViewsController\handler\filter\ShusyVipStatusViewsFilter;
use EntityDefaultViewsController;


class ShusyVipViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => ShusyVipEditLinkViewsField::class,
        ],
      ];
      $info[$table]['rebate'] = [
        'title' => '比例折扣 保留2位小数 0(免费)-100(不打折)',
        'help' => '比例折扣 保留2位小数 0(免费)-100(不打折)',
        'real field' => 'rebate',
        'field' => [
          'handler' => ShusyVipRebateViewsField::class,
        ],
      ];
      $info[$table]['amount'] = [
        'title' => '购买价格',
        'help' => '购买价格',
        'real field' => 'amount',
        'field' => [
          'handler' => ShusyVipAmountViewsField::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 禁用 1 启用',
        'help' => '状态 0 禁用 1 启用',
        'real field' => 'status',
        'field' => [
          'handler' => ShusyVipStatusViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyVipStatusViewsFilter::class,
        ],
      ];
      $info[$table]['is_default'] = [
        'title' => '默认 0 否 1 是',
        'help' => '默认 0 否 1 是',
        'real field' => 'is_default',
        'field' => [
          'handler' => ShusyVipIsDefaultViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyVipIsDefaultViewsFilter::class,
        ],
      ];


      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
